package com.zxl.yjb.activity.home.sharemessage;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.zxl.yjb.R;
import com.zxl.yjb.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareMessageInputActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.tv_page_title)
    TextView tv_page_title;
    @BindView(R.id.tv_confirm)
    TextView tv_confirm;
    @BindView(R.id.et_content)
    EditText et_content;

    private String origin = "";
    private String content = "";
    private int limit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sharemessageinput);
        ButterKnife.bind(this);
        origin = getIntent().getStringExtra("origin");
        if (origin == null)
        {
            origin = "";
        }

        content = getIntent().getStringExtra("content");
        limit = getIntent().getIntExtra("limit",0);
        initView();
    }

    @Override
    protected void initView() {


        if("title".equals(origin))
        {
            tv_page_title.setText("输入主题");
            if (limit != 0)
            {
                et_content.setHint("输入主题（"+limit+"字以内）");
                et_content.setFilters(new InputFilter[]{new InputFilter.LengthFilter(limit)});
            }
            else
            {
                et_content.setHint("输入主题");
            }
        }
        else if ("describe".equals(origin))
        {
            tv_page_title.setText("输入详情");
            if (limit != 0)
            {
                et_content.setHint("输入详情（"+limit+"字以内）");
                et_content.setFilters(new InputFilter[]{new InputFilter.LengthFilter(limit)});
            }
            else
            {
                et_content.setHint("输入详情");
            }
        }
        else if ("phone".equals(origin))
        {
            tv_page_title.setText("输入手机号码");
            if (limit != 0)
            {
                et_content.setHint("输入手机号码（"+limit+"字以内）");
                et_content.setFilters(new InputFilter[]{new InputFilter.LengthFilter(limit)});
            }
            else
            {
                et_content.setHint("输入手机号码");
            }
        }




        tv_confirm.setVisibility(View.VISIBLE);
        tv_confirm.setText("完成");

        et_content.setText(content);

    }

    @OnClick({R.id.iv_back, R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_confirm:
                Intent intent = new Intent();
                intent.putExtra("content",et_content.getText().toString());
                setResult(RESULT_OK,intent);
                finish();
                break;
        }
    }
}
